use crate::byte::*;
use crate::huffman::HuffmanResult;
use crate::seq::{error::*, SymbolCompressionModes};

pub struct WorkSpace {
    pub ll_workspace:crate::seq::SeqWorkSpace,
    pub ml_workspace:crate::seq::SeqWorkSpace,
    pub of_workspace:crate::seq::SeqWorkSpace,
    pub huffman_table:Option<crate::huffman::HuffmanTable>,
}

impl WorkSpace {
    pub fn new() -> Self {
        Self { 
            ll_workspace:crate::seq::SeqWorkSpace::new(),
            ml_workspace:crate::seq::SeqWorkSpace::new(),
            of_workspace:crate::seq::SeqWorkSpace::new(),
            huffman_table:None,
         }
    }

    pub fn load_seq_workspace<R:ByteRead>(&mut self, mode:SymbolCompressionModes, reader:&mut ByteReader<R>, total_len:&mut u32) -> SeqResult<()> {
        self.ll_workspace.load(crate::seq::SeqField::LiteralsLength, mode.literal_lengths_mode(), reader, total_len)?;
        self.of_workspace.load(crate::seq::SeqField::OffsetCodes, mode.offsets_mode(), reader, total_len)?;
        self.ml_workspace.load(crate::seq::SeqField::MatchLength, mode.match_lengths_mode(), reader, total_len)?;
        Ok(())
    }

    pub fn load_huffman_table(&mut self, raw_data:&[u8]) -> HuffmanResult<usize> {
        let (huffman_table, read_bytes_num) = crate::huffman::HuffmanTable::deserialize_from(raw_data)?;
        self.huffman_table = Some(huffman_table);
        Ok(read_bytes_num)
    }
}

pub struct OutputWorkSpace {

}

impl OutputWorkSpace {
    pub fn new() -> Self {
        Self {  }
    }

    pub fn dict_content(&self) -> &[u8] {
        unimplemented!()
    }
}